import { mockReq, cnodeReq, Timeout } from "../services/example";
export default {
  namespace: "example",

  state: {
    n: 111,
  },

  subscriptions: {
    setup({ dispatch, history }) {
      // eslint-disable-line

      console.log(dispatch, history);
    },
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      // eslint-disable-line
      yield put({ type: "save" });
    },
    *incAsync({ payload }, { call, put }) {
      let timeout = yield call(Timeout);
      console.log("延时器结束", timeout);
      let mock = yield call(mockReq);
      console.log("mock数据获取", mock);
      let cnode = yield call(cnodeReq);
      console.log("cnode数据获取", cnode);
      yield put({
        type: "inc", //因为在这个模块内,不用写namespace
      });
    },
  },

  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
    inc(state, action) {
      console.log(action);
      return { ...state, n: state.n + 1 };
    },
  },
};
